//
// Created by 谢哲 on 2021/5/18.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
using namespace std;

int n, m;
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
bool visited[1510][1510];
pair<int,int> visited_value[1510][1510];
int map_data[1510][1510] = {0};

bool dfs(int i, int j) {
    int k;
    if (i>=0&&i<n&&j>=0&&j<m) k=1;
    else k = 2;

    int ci = (i%n+n)%n, cj = (j%m+m)%m;
    int ni = int(floor(double(i)/double(n))), nj = int(floor(double(j)/double(m)));
    if (map_data[ci][cj]) return false;
    if (!visited[ci][cj]) {
        visited[ci][cj] = true;
        visited_value[ci][cj] = make_pair(ni, nj);
    }
    else if (visited_value[ci][cj]==make_pair(ni, nj)) {
        return false;
    }
    else {
        return true;
    }

    for (int a=0;a<4;++a) {
        int nx = i+dx[a], ny=j+dy[a];
        bool result = dfs(nx, ny);
        if (result) return true;
    }

    return false;
}

int main() {
    while(cin >> n >> m) {
        memset(visited, 0, sizeof(visited));
        memset(map_data, 0, sizeof(map_data));

        int sx,sy;
        for (int i=0;i<n;++i) {
            for (int j=0;j<m;++j) {
                char c;
                cin >> c;
                if (c=='#') map_data[i][j] = 1;
                if (c=='S') {
                    sx = i, sy = j;
                }
            }
        }

        if (dfs(sx, sy)) cout << "Yes\n";
        else cout << "No\n";
    }

    return 0;
}
